package com.contract.management.service;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.contract.management.bean.RetMsg;
import com.contract.management.domain.CommJpaRepository;
import com.contract.management.domain.User;

@Service
public class UserService {
	@Autowired
	private CommJpaRepository repo;
	
	public User checkLogin(String username, String password) {
		return repo.queryOne("from User where username = ?0 and password = ?1", username, password);
	}
	
	@Transactional
	public int changePassword(String oldPassword, String password, int id) {
		String op = repo.queryOne("select password from User where id = ?0", id);
		if(!op.equals(oldPassword)) {
			return -1;
		}
		return repo.queryUpdate("update User set password = ?0 where id = ?1", password, id);
	}
}